import request from '@/util/axios'
import type {CommonResultType,QueryItem,ListData,CostAllocationList,AddDataItem,CostAllocationItem,SuccessResultType,AccountingSubjectItem,AccountingSubject,AccountingSubjectDetailItem} from './type'
import type {LocationQueryValue} from "vue-router";
export enum API {
    // 凭证管理-列表
    LIST ='/platform-entry/api/cost_aggregation/credential_management/credential/list',
    DETAIL ='/platform-entry/api/cost_aggregation/credential_management/credential/detail',
    // 凭证管理-新增
    ADD ='/platform-entry/api/cost_aggregation/credential_management/credential/create',
    // 凭证管理-删除
    DELETE ='/platform-entry/api/cost_aggregation/credential_management/credential/delete',
    //凭证管理-更新
    UPDATE ='/platform-entry/api/cost_aggregation/credential_management/credential/update',
    //查会计科目一级
    GET_ACCOUNTING_SUBJECT ='/platform-entry/api/cost_aggregation/credential_management/list',
    //查会计科目二级
    GET_ACCOUNTING_SUBJECT_DETAIL ='/platform-entry/api/cost_aggregation/credential_management/second_list',

    //分摊删除
    DELETE_COST ='/platform-entry/api/cost_aggregation/credential_management/credential_accounting_subject/delete',
    //分摊更新
    UPDATE_COST ='/platform-entry/api/cost_aggregation/credential_management/credential_accounting_subject/update',
    //分摊新增
    ADD_COST ='/platform-entry/api/cost_aggregation/credential_management/credential_accounting_subject/add',


    //关联数据列表
    GET_CORRELATION_LIST ='/platform-entry/api/cost_aggregation/credential_management/credential/relation/list',
    //关联数据删除
    DELETE_CORRELATION ='/platform-entry/api/cost_aggregation/credential_management/credential/relation/delete',
    //关联数据新增
    ADD_CORRELATION ='/platform-entry/api/cost_aggregation/credential_management/credential/relation/create',
    //关联数据更新
    UPDATE_CORRELATION ='/platform-entry/api/cost_aggregation/credential_management/credential/relation/update',
}

/**
 * @method  getAccountingSubject,getAccountingSubjectDetail 查会计一二级
 */
export const getAccountingSubject = (): Promise<AccountingSubject<AccountingSubjectItem>> => {
    return request.get(API.GET_ACCOUNTING_SUBJECT);
};
export const getAccountingSubjectDetail = (params:any): Promise<AccountingSubject<AccountingSubjectDetailItem>> => {
    return request.get(API.GET_ACCOUNTING_SUBJECT_DETAIL,{ params });
};


/**
 * @method  getList 凭证管理-列表
 */
export const getList = (params: QueryItem): Promise<CommonResultType<ListData>> => {
    return request.get(API.LIST, { params });
};

/**
 * @method  addData 凭证管理-添加
 */
export const addData = (params: AddDataItem<CostAllocationItem>): Promise<SuccessResultType> => {
    return request.post(API.ADD,  params );
};

/**
 * @method  getDetail 凭证管理-详情
 */
export const getDetail = (params: string): Promise<AccountingSubject<AddDataItem<CostAllocationItem>>> => {
    return request.get(`${API.DETAIL}?credential_id=${params}`);
};
/**
 * @method  deleteEvent 凭证管理-删除
 */
export const deleteEvent = (params: string): Promise<SuccessResultType> => {
    return request.get(`${API.DELETE}?id=${params}`);
};

/**
 * @method  updateData 凭证管理-更新
 */
export const updateData = (params: AddDataItem<CostAllocationItem>): Promise<SuccessResultType> => {
    return request.post(API.UPDATE, params);
}




/**
* @method  deleteCost 凭证管理-分摊删除
*/
export const deleteCost = (params: string): Promise<SuccessResultType> => {
    return request.get(`${API.DELETE_COST}?cost_accounting_subject_id=${params}`);
};


/**
 * @method  addCost 凭证管理-分摊添加
 */
export const addCost = (params: { summary: any; amount: any; accounting_subject: any; accounting_subject_code: any; accounting_subject_detail: any; credential_id: string | null | LocationQueryValue[] }): Promise<SuccessResultType> => {
    return request.post(API.ADD_COST, params);
};


/**
 * @method  updateCost 凭证管理-分摊更新
 */
export const updateCost = (params: { summary: any; amount: number; cost_accounting_subject_id: any; accounting_subject: any; id: any; accounting_subject_code: any; accounting_subject_detail: any; credential_id: string | null | LocationQueryValue[] }): Promise<SuccessResultType> => {
    return request.post(API.UPDATE_COST, params);
};



/**
 * @method  getCorrelationList 关联数据列表-列表
 */

export const getCorrelationList = (params: string): Promise<AccountingSubject<CostAllocationList>> => {
    return request.get(`${API.GET_CORRELATION_LIST}?credential_id=${params}`);
}
